package com.pentalog.stock.dao2.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.pentalog.stock.dao2.AppUserDao;
import com.pentalog.stock.model.AppUser;

@Repository("appUserDao")
public class AppUserDaoImpl extends BaseDAO2 implements AppUserDao {

	public void save(AppUser appUser) {
		getHibernateTemplate().save(appUser);
	}

	public void update(AppUser appUser) {
		getHibernateTemplate().saveOrUpdate(appUser);
	}

	public void delete(AppUser appUser) {
		getHibernateTemplate().delete(appUser);
	}

	@SuppressWarnings("unchecked")
	public AppUser findByUserName(String userName) {
		List<AppUser> listUsers = getHibernateTemplate().find(
				"From AppUser Where username = ?", userName);
		if (listUsers != null & !listUsers.isEmpty()) {
			return listUsers.get(0);
		} else {
			return null;
		}
	}

	@SuppressWarnings("unchecked")
	public List<AppUser> getAllAppUsers() {
		return getHibernateTemplate().find("From AppUser");
	}

}
